﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;
using System.Data.Odbc;
using Sweat.Service;

public partial class Login : System.Web.UI.Page
{

    StudentService service = new StudentService();
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        lblError.Text = "";
        if (Page.IsValid)
        {
            StudentDTO student = service.Login(txtUserName.Text, txtPassword.Text);
            if (student != null)
            {
                StudentDTO s = service.getStudent(student.Email);
                Session["studentid"] = s.Studentid;
                Session["studentnummer"] = s.Studentnummer;
                Session["naam"] = s.Naam + s.Voornaam;
                Session["status"] = "loggedin";
                lblError.Text = " U bent succesvol ingelogd";
                Response.Redirect("Examens.aspx");
            }
            else
            {
                lblError.Text = "Username en/of wachtwoord is verkeerd!";
            }
        }

        

    }
    protected void txtUserName_TextChanged(object sender, EventArgs e)
    {
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        /*string connectString = "Driver={MySQL ODBC 3.51 Driver};uid=sweat;password=sweat;Server=127.0.0.1;Option=16834;Database=sweat;";
        OdbcConnection con = new OdbcConnection(connectString);
        con.Open();
        string sql = "select * from bla";
        OdbcDataAdapter cmd = new OdbcDataAdapter(sql, con);

        con.Close();*/
    }
}
